/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved.
 * Description: ES业务dfx实现
 * Author: liutianming
 * Create: 2024-08-08
 */

#include "es_utils.h"
#include "log.h"

#include <cstdlib>
#include <slog.h>
#include <slog_api.h>


using namespace std;
namespace hccl {

void EsUtils::PrintEsKvDataSummary(const std::string &printInfo, float *valueBuffer, u64 keyCount,
    u32 valueDim, s64 *keys)
{
    if (valueBuffer == nullptr || keys == nullptr) {
        HCCL_WARNING("valueBuffer or keys is nullptr, please check param.");
        return;
    }

    for (u64 i = 0; i < keyCount; i++) {
        double valueSum = 0;
        float minValue = FLT_MAX;
        float maxValue = FLT_MIN;
        for (u32 j = 0; j < valueDim; j++) {
            float curValue = *(valueBuffer + j);
            maxValue = curValue >  maxValue ? curValue : maxValue;
            minValue = curValue <  minValue ? curValue : minValue;
            valueSum += curValue;
        }
        valueBuffer = valueBuffer + valueDim;
        HCCL_ERROR("%s key[%lld] value:valueSum[%lf] count[%d] avg[%lf] minValue[%f] maxValue[%f]", printInfo.c_str(),
            keys[i], valueSum, keyCount, valueSum / valueDim, minValue, maxValue);
    }
}
}